package com.example.controller;

import cn.hutool.db.sql.Order;
import com.example.entity.TOrder;

import com.example.service.ITOrderService;
import com.hzit.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.net.URI;
import java.util.List;


@RestController
@RequestMapping("/tOrder")
public class TOrderController {
    @Autowired
    private ITOrderService itOrderService;
    @Resource
    private LoadBalancerClient client;

    //查询商品列表
    @GetMapping("/list")
    public R<List<TOrder>> list(){
        //URI uri = client.choose("order").getUri();
        return R.ok(itOrderService.list());
    }
    @PostMapping("/add")
    public R add(@RequestBody TOrder order){
        boolean flag = itOrderService.save(order);
        return flag ? R.ok("添加成功") : R.fail("添加失败");
    }
    @PutMapping("/update")
    public R update(@RequestBody TOrder order){
        boolean flag = itOrderService.updateById(order);
        return flag ? R.ok("修改成功") : R.fail("修改失败");
    }
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Integer id){
        boolean flag = itOrderService.removeById(id);
        return flag ? R.ok("删除成功") : R.fail("删除失败");
    }
}
